'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.getDefaultData = exports.getDefaultStyleObj = exports.getDefaultValue = undefined;

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _utils = require('./utils');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var getDefaultValue = exports.getDefaultValue = function getDefaultValue(dom, isMobile, state) {
    var domStyle = void 0;
    if (state !== 'default') {
        domStyle = (0, _extends3['default'])({}, (0, _utils.getDomCssRule)({ dom: dom, isMobile: isMobile, state: state }));
    } else {
        domStyle = (0, _utils.getDomCssRule)({ dom: dom, isMobile: isMobile });
    }

    return domStyle;
};

var getDefaultStyleObj = exports.getDefaultStyleObj = function getDefaultStyleObj(dom, isMobile) {
    var state = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'default';

    // 当前带样式的 value;
    var domStyle = getDefaultValue(dom, isMobile, state);
    return getDefaultData(domStyle);
};

var getDefaultData = exports.getDefaultData = function getDefaultData(style) {
    if (!style) {
        return null;
    }
    var borderBool = style.borderStyle !== 'none' && style.borderColor !== '0px' || style.borderTopStyle !== 'none' && style.borderTopColor !== '0px' || style.borderRightStyle !== 'none' && style.borderRightColor !== '0px' || style.borderBottomStyle !== 'none' && style.borderBottomColor !== '0px' || style.borderLeftStyle !== 'none' && style.borderLeftColor !== '0px';
    var result = {
        state: {
            cursor: style.cursor || 'auto'
        },
        layout: {
            display: style.display,
            // 只支持 row 布局
            alignItems: style.alignItems || 'stretch',
            justifyContent: style.justifyContent || 'flex-start'
        },
        font: {
            family: style.fontFamily,
            size: style.fontSize,
            weight: (0, _utils.convertData)(style.fontWeight) || 'normal',
            lineHeight: (0, _utils.convertData)(style.lineHeight),
            color: (0, _utils.convertDefaultData)(style.color),
            letterSpacing: (0, _utils.convertData)(style.letterSpacing),
            align: (0, _utils.convertDefaultData)(style.textAlign) || 'left',
            decoration: (0, _utils.convertData)(style.textDecoration || style.textDecorationLine) || 'none'
        },
        'interface': {
            overflow: (0, _utils.convertDefaultData)(style.overflow) || 'visible',
            width: (0, _utils.convertData)(style.width),
            maxWidth: (0, _utils.convertData)(style.maxWidth),
            minWidth: (0, _utils.convertData)(style.minWidth),
            height: (0, _utils.convertData)(style.height),
            maxHeight: (0, _utils.convertData)(style.maxHeight),
            minHeight: (0, _utils.convertData)(style.minHeight),
            position: (0, _utils.convertDefaultData)(style.position) || 'static',
            top: (0, _utils.convertDefaultData)((0, _utils.convertData)(style.top, true)),
            right: (0, _utils.convertDefaultData)((0, _utils.convertData)(style.right, true)),
            bottom: (0, _utils.convertDefaultData)((0, _utils.convertData)(style.bottom, true)),
            left: (0, _utils.convertDefaultData)((0, _utils.convertData)(style.left, true)),
            zIndex: style.index || 0,
            float: style.float || 'none',
            clear: style.clear || 'none',
            opacity: parseFloat(style.opacity) === 0 || parseFloat(style.opacity) ? parseFloat(style.opacity) : 1
        },
        background: {
            color: (0, _utils.convertDefaultData)(style.backgroundColor),
            image: (0, _utils.getBgDefaultData)(style)
        },
        border: {
            style: (0, _utils.convertBorderData)(style.borderStyle || (style.borderTopStyle || style.borderRightStyle || style.borderBottomStyle || style.borderLeftStyle ? {
                top: style.borderTopStyle,
                right: style.borderRightStyle,
                bottom: style.borderBottomStyle,
                left: style.borderLeftStyle
            } : null), style.borderWidth) || 'none',
            color: borderBool && (0, _utils.convertBorderData)(style.borderColor || (style.borderTopColor || style.borderRightColor || style.borderBottomColor || style.borderLeftColor ? {
                top: style.borderTopColor,
                right: style.borderRightColor,
                bottom: style.borderBottomColor,
                left: style.borderLeftColor
            } : null), style.borderWidth) || null,
            width: (0, _utils.convertBorderData)(style.borderWidth || (style.borderTopWidth || style.borderRightWidth || style.borderBottomWidth || style.borderLeftWidth ? {
                top: style.borderTopWidth,
                right: style.borderRightWidth,
                bottom: style.borderBottomWidth,
                left: style.borderLeftWidth
            } : null)),
            radius: (0, _utils.convertBorderData)(style.borderRadius || (style.borderTopLeftRadius || style.borderTopRightRadius || style.borderBottomRightRadius || style.borderBottomLeftRadius ? {
                'top-left': style.borderTopLeftRadius,
                'top-right': style.borderTopRightRadius,
                'bottom-right': style.borderBottomRightRadius,
                'bottom-left': style.borderBottomLeftRadius
            } : null), null, true)
        },
        margin: {
            margin: (0, _utils.convertBorderData)(style.margin || {
                top: style.marginTop,
                right: style.marginRight,
                bottom: style.marginBottom,
                left: style.marginLeft
            }),
            padding: (0, _utils.convertBorderData)(style.padding || {
                top: style.paddingTop,
                right: style.paddingRight,
                bottom: style.paddingBottom,
                left: style.paddingLeft
            })
        },
        shadow: {
            boxShadow: (0, _utils.convertShadowData)(style.boxShadow),
            textShadow: (0, _utils.convertShadowData)(style.textShadow)
        },
        transition: style.transition
    };
    return result;
};